package com.youku.expression.ast;

import com.youku.expression.environment.Environment;

public class AssignAst extends StatementAst {

	public AssignAst(Ast var, Ast exp) {
		super(var, exp);
	}

	public Ast getVar() {
		return getChild(0);
	}

	public String varValue() {
		return getVar().getTokenValue();
	}

	public Ast getExp() {
		return getChild(1);
	}

	@Override
	public String toString() {
		return getVar() + "= " + getExp();
	}

	@Override
	public Object eval(Environment environment) {
		IdentifierAst primary=(IdentifierAst) getVar();
		
		Object value = getExp().eval(environment);
		environment.put(primary.getTokenValue(), value);
		return value;
	}

}
